using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace SeataNet.Core.Lock
{
    /// <summary>
    /// 全局锁服务扩展
    /// </summary>
    public static class LockServiceExtensions
    {
        /// <summary>
        /// 添加全局锁服务
        /// </summary>
        public static IServiceCollection AddGlobalLock(this IServiceCollection services)
        {
            // 注册全局锁管理器
            services.TryAddSingleton<IGlobalLockManager, InMemoryGlobalLockManager>();

            return services;
        }

        /// <summary>
        /// 添加全局锁服务（使用自定义实现）
        /// </summary>
        public static IServiceCollection AddGlobalLock<TLockManager>(this IServiceCollection services)
            where TLockManager : class, IGlobalLockManager
        {
            services.TryAddSingleton<IGlobalLockManager, TLockManager>();

            return services;
        }
    }
}
